/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-04-03
 * Time:23:30
 */

/**
 *  public boolean hasCycle(ListNode head) {
 *         ListNode cur1 = head;
 *         ListNode cur2 = head;
 *         while (cur1 != null && cur1.next != null){
 *             cur1 = cur1.next.next;
 *             cur2 = cur2.next;
 *             if (cur1 == cur2){
 *                 return true;
 *             }
 *         }
 *         return false;
 *     }
 */

/**
 * BM6 判断链表中是否有环
 */

public class hasCycle {
    public boolean hasCycle(ListNode head) {
        ListNode cur1 = head;
        ListNode cur2 = head;
        while (cur1 != null && cur1.next != null){
            cur1 = cur1.next.next;
            cur2 = cur2.next;
            if (cur1 == cur2){
                return true;
            }
        }
        return false;
    }
}
